package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/02 19:08
 **/
public class Day18_1_Num622_MyCircularQueue {
    class MyCircularQueue {
        // 数组
        int[] data;
        // 索引下标
        int index;
        public MyCircularQueue(int k) {
            data = new int[k];
            index = -1;
        }

        public boolean enQueue(int value) {
            if(isFull()) {
                return false;
            }else {
                index++;
                data[index] = value;
                return true;
            }
        }

        public boolean deQueue() {
            if(isEmpty()) {
                return false;
            }else {
                for(int i = 0;i < index;i++){
                    data[i] = data[i+1];
                }
                index--;
                return true;
            }
        }

        public int Front() {
            if(isEmpty()) return -1;
            else return data[0];
        }

        public int Rear() {
            if(isEmpty()) return -1;
            else return data[index];
        }

        public boolean isEmpty() {
            return index == -1 ? true : false;
        }

        public boolean isFull() {
            return index == data.length-1 ? true : false;
        }
    }
}